package com.tckdq.tcc.service.impl;

import com.tckdq.tcc.domain.MessageSms;
import com.tckdq.tcc.mapper.MessageSmsMapper;
import com.tckdq.tcc.service.IMessageSmsService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author whale
 * @since 2022-08-15
 */
@Service
public class MessageSmsServiceImpl extends ServiceImpl<MessageSmsMapper, MessageSms> implements IMessageSmsService {

    @Override
    public void save(String phone,String code) {
        MessageSms messageSms = new MessageSms();
        messageSms.setTitle("注册1验证码");
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        String addr = attributes.getRequest().getRemoteAddr();
        messageSms.setIp(addr);
        messageSms.setSendTime(new Date());
        messageSms.setPhone(phone);
        messageSms.setContent(code);
        insert(messageSms);
    }
}
